#!/usr/bin/perl 
#file:  hc_function.pl
#time:  2008.09
#author: joecen
#site:  http://www.joecen.com/hcacti

sub HTTP_GET {
        my $url         = $_[0];
        my $agent       = LWP::UserAgent->new;
	$agent->agent("HCacti perl/0.1");
        my $request     = HTTP::Request->new(GET => $url);
        my $response    = $agent->request($request);
        $response->is_success or die(&GET_TIME," ",$url,": ",$response->code," ",$response->message,"\n");
        $response->content;
}

sub hcacti_log {
	my $log_name 	= "./logs/hcacti.log";
	my $string	= &GET_TIME." ".$_[0]."\n";
	die(&GET_TIME." Error:Couldn't open file '".$log_name."'\n") if(! open LOG,">>$log_name");
	print LOG $string;
	print $string if ($_[1] eq "True");
}

sub HTTP_POST {
        my $url         = $_[0];
        my $agent       = LWP::UserAgent->new;
	$agent->agent("HCacti perl/0.1");
        my $request     = HTTP::Request->new(POST => $url);
	$request->content_type('application/x-www-form-urlencoded');
	$request->content('$_[1]');
        my $response    = $agent->request($request);
        $response->is_success or die(&GET_TIME," ",$url,": ",$response->code," ",$response->message,"\n");
        $response->content;
}

sub GET_TIME{
	(@date)=localtime;
	$date[5]+=1900;$date[4]++;
	$now=sprintf("[%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d]",$date[5],$date[4], $date[3], $date[2],$date[1],$date[0]);
	$now;
}

sub MD5SUM{
	use Digest::MD5;

	open FILE,$_[0] or die(&GET_TIME," Counld check File '",$_[0],"' md5",$!,"\n");
	$md5 = Digest::MD5->new;
	$md5->addfile(*FILE);
	$md5->hexdigest;
}

1;
